﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using SQLServerHealthCheck.Model;

namespace SQLServerHealthCheck.SQLServer.IssueTypes
{
    public class IssueTypesFactory
    {
        public static List<IssueTypeCheckBase> GetAllChecks()
        {
            List<IssueTypeCheckBase> checks = new List<IssueTypeCheckBase>();

            //Add if constructions to dynamically add or remove checks for example with checkboxes in the GUI
            try
            {


                HealthCheckDataContext dc = new HealthCheckDataContext(System.Configuration.ConfigurationManager.AppSettings["ConnectionStringSSHCDatabase"].ToString());
     

                Assembly asm = Assembly.Load("SQLServerHealthCheck.SQLServer");

                var qry = from t in asm.GetTypes()
                          where t.IsClass && t.Namespace == "SQLServerHealthCheck.SQLServer.IssueTypes" && t.BaseType.Name == "IssueTypeCheckBase"
                          select t;

                var enabled = from a in dc.IssueTypes
                              where a.Enabled == true
                              select a.IssueTypeId;

                foreach (var item in qry)
                {
                    IssueTypeCheckBase check = (IssueTypeCheckBase)Activator.CreateInstance(item);
                    if (enabled.Contains(check.IssueTypeId))
                    {
                        checks.Add(check);
                    }
                }
            //    checks.Add(new ServerCheckFreeSpaceLess10percent());//1001
            //    checks.Add(new ServerMorethanOneInstanceRunning()); //1002
            //    checks.Add(new ServiceCheckMaintenancePlanWithAutoShrink());//2011
            //    checks.Add(new ServiceCheckMaintenancePlanWithRebuildIndex());//2012
            //    checks.Add(new ServiceCheckNoMaintenancePlanWithReorganizeIndex());//2013
            //    checks.Add(new ServiceCheckNotLatestServicePack()); //2001
            //    checks.Add(new ServiceCheckTooManyDatabaseOwners()); //2002
            //    checks.Add(new ServiceCheckTempDBdatafilesLessProcessorsCount()); //IssueType 2004           
            //    checks.Add(new ServiceCheckOleAutomationEnabled()); //IssueType 2005
            //    checks.Add(new ServiceCheckUserConnectionsNotDefault()); //IssueType 2008
            //    checks.Add(new ServiceCheckXPcmdshellEnabled()); // 2006
            //    checks.Add(new ServiceCheckMixedAuthenticationMode()); // IssueType 2007
            //    checks.Add(new ServiceCheckTempdbOnSameDriveasDatafile()); //2010
            //    checks.Add(new ServiceRestartedLessThanMonthAgo()); //2014
            //    checks.Add(new SecurityCheckUserOrphanedDatabaseUsers()); //9001
            //    checks.Add(new SecurityCheckTooManySysAdminLogins()); //2003
            //    checks.Add(new ServiceCheckFailedMaintenancePlan());//2015
            //    checks.Add(new ServiceCheckTooManyBackupsOnTheSameDrive());//2017
            //    checks.Add(new ServiceCheckCXPACKET());//2018
            //    checks.Add(new DatabaseCheckFullRecoveryModelWithNoLogBackup()); //3001
            //    checks.Add(new DatabaseCheckNoRecentBackup()); //3002
            //    checks.Add(new DatabaseCheckMdfFileonCdrive()); //3003
            //    checks.Add(new DatabaseCheckStateOffline()); //3004
            //    checks.Add(new DatabaseCheckLogFileSizetoData()); //3005
            //    checks.Add(new DatabaseCheckCompatibilityLevel()); //3006
            //    checks.Add(new DatabaseCheckDataAndLogonSameDrive()); //3007
            //    checks.Add(new DatabaseAutoGrowthLess10percentDBsize());// 3010
            //    checks.Add(new DatabaseCheckAutoShrinkStateOn()); // Issue Type 3011
            //    checks.Add(new DatabaseCheckPageVerifySetToNone()); //Issue 3012
            //    checks.Add(new DatabaseCheckMaxFileGrowthStateOn()); //IssueTypeCheckBase Type 3009
            //    checks.Add(new DatabaseCheckAutoUpdateOff()); // 3013
            //    checks.Add(new PerformanceCheckFragmentedClusteredIndexes());//6001
            //    checks.Add(new PerformanceCheckHasNoClustered());// Issue Type 5002
            //    checks.Add(new PerformanceCheckUnusedNonClusteredIndexes());//6002
            //    checks.Add(new DatabaseCheckCollationCompability());//3014
            //    checks.Add(new DatabaseCheckSlowBackup());//3015
            //    checks.Add(new DatabaseCheckNoNonClusteredIndexes());//3016 
            //    checks.Add(new DatabaseAutoGrowthOff()); //3017
            //    checks.Add(new DatabaseCheckDatabaseSnapshots()); //3019
            //    checks.Add(new DatabaseCheckTooLittleRelations()); //3018
            //    checks.Add(new ServiceCheckMaxMemorySetting()); //2019
                
            }
            catch (Exception ex)
            { 
            
                  
             
            
            }
            return checks;
        }
    }

}
